<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title a m-cf">门店线下支付列表</div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom am-cf">
                    </div>
                    <div class="am-scrollable-horizontal am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>门店</th>
                                <th>订单号</th>
                                <th>用户</th>
                                <th>金额</th>
                                <th>赠送积分</th>
                                <th>支付状态</th>
                                <th>提交时间</th>
                                <th>支付时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle"><?= $item['order_id'] ?></td>
                                    <td class="am-text-middle"><?= $item['shop']['shop_name'] ?></td>
                                    <td class="am-text-middle"><?= $item['order_no'] ?></td>
                                    <td class="am-text-middle"><?= $item['user']['nickName'] ?></td>
                                    <td class="am-text-middle"><?= $item['pay_price'] ?></td>
                                    <td class="am-text-middle"><?= $item['gift_money'] ?></td>
                                    <td class="am-text-middle">
                                        <span class="am-badge
                                        <?= $item['pay_status']['value'] == 20 ? 'am-badge-success' : '' ?>">
                                                <?= $item['pay_status']['text'] ?></span></td>
                                    <td class="am-text-middle"><?= date('Y-m-d H:i:s',$item['addtime']) ?></td>
                                    <td class="am-text-middle"><?= date('Y-m-d H:i:s',$item['pay_time']) ?></td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <?php if (checkPrivilege('payorder/refund')): ?>
                                                <a class="j-recharge tpl-table-black-operation-default"
                                                   href="javascript:void(0);"
                                                   title="退款"
                                                   data-id="<?= $item['order_id'] ?>"
                                                   data-balance="<?= $item['pay_price'] ?>"
                                                   data-points="<?= $item['gift_money'] ?>"
                                                >
                                                    <i class="iconfont icon-qiandai"></i>
                                                    退款
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="9" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script id="tpl-recharge" type="text/template">
    <div class="am-padding-xs am-padding-top-sm">
        <form class="am-form tpl-form-line-form" method="post" action="">
            <div class="j-tabs am-tabs">

                <div class="am-tabs-bd am-padding-xs">

                    <div class="am-tab-panel am-padding-0 am-active" id="tab1">
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                付款金额
                            </label>
                            <div class="am-u-sm-8 am-u-end">
                                <div class="am-form--static">{{ balance }}</div>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                获得积分
                            </label>
                            <div class="am-u-sm-8 am-u-end">
                                <div class="am-form--static">{{ points }}</div>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                退款金额
                            </label>
                            <div class="am-u-sm-8 am-u-end">
                                <input type="number" min="0" class="tpl-form-input"
                                       placeholder="请输入要退款的金额" oninput="getValue($(this),{{ balance }})" name="money" value="" required>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                扣除积分
                            </label>
                            <div class="am-u-sm-8 am-u-end">
                                <div class="am-form--static" id="jifen">0</div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </form>
    </div>
</script>
<script>
    function getValue(obj,balance){
        console.log(obj.val())
        console.log(balance)
        if(balance < parseFloat(obj.val()) ){
            $.show_error('您输入的退款金额不能大于付款金额')
        }
        //计算应该扣除的积分
        $.ajax({
            type:'post',
            dataType:'json',
            data: {money:obj.val(),wxapp_id:10001},
            url:"/index.php?s=/api/pay/integraljisuan",
            success:function (data) {
                $('#jifen').html(data.data.integral+'积分')
            }
        })
    }
    $(function () {
        /**
         * 退款
         */
        $('.j-recharge').on('click', function () {
            var $tabs, data = $(this).data();
            $.showModal({
                title: '退款'
                , area: '460px'
                , content: template('tpl-recharge', data)
                , uCheck: true
                , success: function ($content) {
                    $tabs = $content.find('.j-tabs');
                    $tabs.tabs({noSwipe: 1});
                }
                , yes: function ($content) {
                    $content.find('form').myAjaxSubmit({
                        url: '<?= url('shop.payorder/refund') ?>',
                        data: {
                            order_id: data.id
                        }
                    });
                    return true;
                }
            });
        });

    });
</script>
